package com.example.dingtalklogin.manager.dingtalk;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

/**
 * 钉钉新版api的client声明
 * token拦截器自动传入
 * @author xuzhen97
 */
@FeignClient(
        name = "dingtalkClient",
        url = "https://api.dingtalk.com",
        configuration = DingtalkApiConfig.class
)
@Component
public interface DingtalkApiClient {

    /**
     * 获取用户通讯录个人信息
     * https://open.dingtalk.com/document/personalapp-server/retrieve-user-information
     * 传入用户token后，想要获取token所属人信息，则 unionId = me
     * @param unionId
     * @return
     */
    @GetMapping("/v1.0/contact/users/{unionId}")
    UserInfoResponse getUserInfo(@PathVariable String unionId
            , @RequestHeader("x-acs-dingtalk-access-token") String accessToken);

    /**
     * 给机器人发送消息
     * @param request
     * @return
     */
    @PostMapping("/v1.0/robot/groupMessages/send")
    String sendRobotMsg(@RequestBody RobotSendMsgRequest request);

    /**
     * 发送卡片消息
     * @param request
     * @return
     */
    @PostMapping("/v1.0/im/interactiveCards/send")
    InteractiveCardSendResponse sendInteractiveCards(@RequestBody InteractiveCardSendRequest request);
}
